<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class M_corp extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index($name_roman)
	{
		// helper
		$this->load->helper(array('form', 'url'));
		
		//echo $roman_name;
		$this->load->model('Company_model', 'company');
		$id = $this->company->get_id_from_name($name_roman);
		//show_error($id);
		
		$company = $this->company->get_company_info($id);
		$company_meta = $this->company->get_company_meta_info($id);
		
		//show_error(print_r($company));
		$company->images = explode(",", $company->images);
		
		$this->load->view('mobile/temp_corp', array(
			"company" => $company,
			"company_meta" => $company_meta
		));
	}

	public function receive_form($id){
		
		// get company's all info
		$this->load->model('Company_model', 'company');		
		$company = $this->company->get_company_info($id);
		$company_meta = $this->company->get_company_meta_info($id);
		
		$company->images = explode(",", $company->images);
		
		$this->load->helper(array('form', 'url'));

		$this->load->library('form_validation');
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
		
		$this->form_validation->set_rules('name', 'お名前', 'required');
		$this->form_validation->set_rules('furigana', 'フリガナ', 'required');
		$this->form_validation->set_rules('mail', 'メール', 'required');
		$this->form_validation->set_rules('school', '学校名', 'required');
		$this->form_validation->set_rules('gakubu', '学部名', 'required');
		$this->form_validation->set_rules('gakunen', '学年', 'required');
		$this->form_validation->set_rules('eki', '最寄り駅', 'required');

		// $info push to check page
		$info["お名前"] = $_POST["name"];
		
		$info["フリガナ"] = $_POST["furigana"];
		
		$info["メールアドレス(PC)"] = $_POST["mail"];
		
		$info["電話番号"] = $_POST["phone"];
		
		$info["学校名"] = $_POST["school"];
		
		$info["学部名"] = $_POST["gakubu"];
		
		$info["学年"] = $_POST["gakunen"];
		
		$info["最寄り駅"] = $_POST["eki"];
		
		$info["twitterアカウント"] = $_POST["twitter"];
		
		$info["志望理由"] = $_POST["reasons"];
		
		$info["自己PR"] = $_POST["selfPR"];
		
		$info["成功体験"] = $_POST["success-exp"];
		
		if ($this->form_validation->run() == FALSE)
		{
			$this->load->view('mobile/temp_corp', array(
				"company" => $company,
				"company_meta" => $company_meta
			));
		}
		else
		{
			//$this->load->view('formsuccess');
			$this->load->view('mobile/form_kakunin', array(
				"info" => $info,
				"post" => $_POST,
				"company" => $company
			));
		}
	}

	public function send_form($id){
		$this->load->model('Company_model', 'company');		
		$company = $this->company->get_company_info($id);
		
		// $info push to check page
		$info["お名前"] = $_POST["name"];
		
		$info["フリガナ"] = $_POST["furigana"];
		
		$info["メールアドレス(PC)"] = $_POST["mail"];
		
		$info["電話番号"] = $_POST["phone"];
		
		$info["学校名"] = $_POST["school"];
		
		$info["学部名"] = $_POST["gakubu"];
		
		$info["学年"] = $_POST["gakunen"];
		
		$info["最寄り駅"] = $_POST["eki"];
		
		$info["twitterアカウント"] = $_POST["twitter"];
		
		$info["志望理由"] = $_POST["reasons"];
		
		$info["自己PR"] = $_POST["selfPR"];
		
		$info["成功体験"] = $_POST["success-exp"];
		
		$mailcontent = "";
		foreach ($info as $key => $value) {
			$mailcontent .= "$key: $value\n";
		}
		//echo nl2br($mailcontent);
		
		$this->load->library('email');
		
		$this->email->from('your@example.com', 'Intern55');
		$this->email->to('nishimura@berryinc.jp'); 
		$this->email->cc('another@another-example.com');
		$this->email->bcc('them@their-example.com');
		
		$this->email->subject( "インターンシップお問い合わせ　".$company->kaisha_mei );
		$this->email->message($mailcontent);
		
		//echo $this->email->print_debugger();
		if ( $this->email->send() )
			$this->load->view('mobile/thanks', array(
			));
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */